package com.egg.ylt.adapter.record;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.egg.ylt.R;
import com.egg.ylt.Utils.Constants;
import com.egg.ylt.Utils.StringUtil;
import com.egg.ylt.pojo.BabyDynamicMsgEntity;
import com.egg.ylt.presenter.impl.RecordPresenter;
import com.google.zxing.common.StringUtils;
import com.yonyou.framework.library.adapter.rv.ItemViewDelegate;
import com.yonyou.framework.library.adapter.rv.ViewHolder;

import java.math.BigDecimal;

/**
 * Created By Dlx
 * on 2019/1/19
 */
public class RecordHeightWeightViewType implements ItemViewDelegate<BabyDynamicMsgEntity.ListBean> {
    private RecordPresenter mPreseneter;

    public RecordHeightWeightViewType(RecordPresenter mPreseneter) {
        this.mPreseneter = mPreseneter;
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.item_record_height_weight_info;
    }

    @Override
    public boolean isForViewType(BabyDynamicMsgEntity.ListBean item, int position) {
        if ("1".equals(item.getRecordType())) {
            return true;
        }
        return false;
    }

    @Override
    public void convert(ViewHolder holder, final BabyDynamicMsgEntity.ListBean listBean, final int position) {
        holder.setText(R.id.record_date_textview, listBean.getDate());
        holder.setText(R.id.record_date_days_textview, listBean.getWeek());
        holder.setText(R.id.item_record_height_tv, "0".equals(listBean.getHeight()) ? "--" : new BigDecimal(StringUtil.get(listBean.getHeight())).toPlainString());
        holder.setText(R.id.item_record_weight_tv, "0".equals(listBean.getWeight()) ? "--" : new BigDecimal(StringUtil.get(listBean.getWeight())).toPlainString());
        holder.setText(R.id.item_record_hw_relationship_tv, listBean.getRelationName());
        holder.setText(R.id.item_record_hw_date_tv, listBean.getTime());
        Glide.with(mPreseneter.getContext()).load(listBean.getBabyUrl()).into((ImageView) holder.getView(R.id.item_record_hw_headiv));
        holder.setOnClickListener(R.id.item_record_delete_iv, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPreseneter.deleteBabyDynamicMsg( listBean.getId(), 0, position);
            }
        });
    }
}
